package com.ocean.linkedlist;

public class ListNode {
    public int val;
    public ListNode next;

    public ListNode() {
    }

    public ListNode(int val) {
        this.val = val;
    }

    ListNode(int val, ListNode next) {
        this.val = val;
        this.next = next;
    }

    @Override
    public String toString() {
        return "ListNode{" +
                "val=" + val +
                '}';
    }

    public static void print(ListNode head) {
        StringBuilder builder = new StringBuilder();
        builder.append(head.val + ",");
        ListNode temp = head;
        while (temp.next != null) {
            temp = temp.next;
            builder.append(temp.val);
            if (temp.next != null) {
                builder.append(",");
            }
        }
        System.out.println(builder);
    }

}
